from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-21 14:02:27.176418
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 21, May, 2022
Time: 14:02:34
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.3634
Nobs: 663.000 HQIC: -49.7372
Log likelihood: 8189.50 FPE: 1.98003e-22
AIC: -49.9738 Det(Omega_mle): 1.73044e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.313671 0.060280 5.204 0.000
L1.Burgenland 0.107125 0.038752 2.764 0.006
L1.Kärnten -0.109528 0.020343 -5.384 0.000
L1.Niederösterreich 0.200716 0.080624 2.490 0.013
L1.Oberösterreich 0.122302 0.079839 1.532 0.126
L1.Salzburg 0.256945 0.041199 6.237 0.000
L1.Steiermark 0.042973 0.054024 0.795 0.426
L1.Tirol 0.101705 0.043504 2.338 0.019
L1.Vorarlberg -0.063499 0.038599 -1.645 0.100
L1.Wien 0.032738 0.070625 0.464 0.643
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.045450 0.128461 0.354 0.723
L1.Burgenland -0.031114 0.082584 -0.377 0.706
L1.Kärnten 0.040622 0.043352 0.937 0.349
L1.Niederösterreich -0.182407 0.171816 -1.062 0.288
L1.Oberösterreich 0.448148 0.170141 2.634 0.008
L1.Salzburg 0.284836 0.087798 3.244 0.001
L1.Steiermark 0.107028 0.115128 0.930 0.353
L1.Tirol 0.311433 0.092711 3.359 0.001
L1.Vorarlberg 0.021721 0.082257 0.264 0.792
L1.Wien -0.037795 0.150507 -0.251 0.802
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.184746 0.030970 5.965 0.000
L1.Burgenland 0.090490 0.019910 4.545 0.000
L1.Kärnten -0.007570 0.010452 -0.724 0.469
L1.Niederösterreich 0.256517 0.041422 6.193 0.000
L1.Oberösterreich 0.155674 0.041019 3.795 0.000
L1.Salzburg 0.042473 0.021167 2.007 0.045
L1.Steiermark 0.024150 0.027756 0.870 0.384
L1.Tirol 0.083807 0.022351 3.750 0.000
L1.Vorarlberg 0.053178 0.019831 2.682 0.007
L1.Wien 0.117603 0.036285 3.241 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109825 0.031003 3.542 0.000
L1.Burgenland 0.046192 0.019931 2.318 0.020
L1.Kärnten -0.014070 0.010463 -1.345 0.179
L1.Niederösterreich 0.185308 0.041467 4.469 0.000
L1.Oberösterreich 0.326831 0.041062 7.959 0.000
L1.Salzburg 0.101839 0.021189 4.806 0.000
L1.Steiermark 0.109122 0.027785 3.927 0.000
L1.Tirol 0.096370 0.022375 4.307 0.000
L1.Vorarlberg 0.059555 0.019852 3.000 0.003
L1.Wien -0.021922 0.036324 -0.604 0.546
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112987 0.057700 1.958 0.050
L1.Burgenland -0.043342 0.037093 -1.168 0.243
L1.Kärnten -0.046164 0.019472 -2.371 0.018
L1.Niederösterreich 0.141336 0.077173 1.831 0.067
L1.Oberösterreich 0.162165 0.076421 2.122 0.034
L1.Salzburg 0.281299 0.039436 7.133 0.000
L1.Steiermark 0.055710 0.051711 1.077 0.281
L1.Tirol 0.164293 0.041642 3.945 0.000
L1.Vorarlberg 0.095955 0.036947 2.597 0.009
L1.Wien 0.077902 0.067602 1.152 0.249
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061358 0.045512 1.348 0.178
L1.Burgenland 0.031866 0.029258 1.089 0.276
L1.Kärnten 0.051280 0.015359 3.339 0.001
L1.Niederösterreich 0.208208 0.060872 3.420 0.001
L1.Oberösterreich 0.316379 0.060279 5.249 0.000
L1.Salzburg 0.041582 0.031106 1.337 0.181
L1.Steiermark 0.006859 0.040788 0.168 0.866
L1.Tirol 0.132052 0.032846 4.020 0.000
L1.Vorarlberg 0.065254 0.029143 2.239 0.025
L1.Wien 0.086015 0.053323 1.613 0.107
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166708 0.054666 3.050 0.002
L1.Burgenland 0.007243 0.035143 0.206 0.837
L1.Kärnten -0.065375 0.018448 -3.544 0.000
L1.Niederösterreich -0.093321 0.073115 -1.276 0.202
L1.Oberösterreich 0.203479 0.072403 2.810 0.005
L1.Salzburg 0.054149 0.037362 1.449 0.147
L1.Steiermark 0.241382 0.048992 4.927 0.000
L1.Tirol 0.502328 0.039453 12.732 0.000
L1.Vorarlberg 0.057978 0.035004 1.656 0.098
L1.Wien -0.072362 0.064047 -1.130 0.259
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.149169 0.060544 2.464 0.014
L1.Burgenland 0.004227 0.038922 0.109 0.914
L1.Kärnten 0.060154 0.020432 2.944 0.003
L1.Niederösterreich 0.181551 0.080977 2.242 0.025
L1.Oberösterreich -0.056831 0.080188 -0.709 0.478
L1.Salzburg 0.206520 0.041380 4.991 0.000
L1.Steiermark 0.134172 0.054260 2.473 0.013
L1.Tirol 0.069990 0.043695 1.602 0.109
L1.Vorarlberg 0.143298 0.038768 3.696 0.000
L1.Wien 0.109572 0.070934 1.545 0.122
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.374002 0.035738 10.465 0.000
L1.Burgenland -0.000109 0.022975 -0.005 0.996
L1.Kärnten -0.021609 0.012060 -1.792 0.073
L1.Niederösterreich 0.217123 0.047799 4.542 0.000
L1.Oberösterreich 0.227801 0.047333 4.813 0.000
L1.Salzburg 0.039131 0.024425 1.602 0.109
L1.Steiermark -0.015850 0.032028 -0.495 0.621
L1.Tirol 0.093218 0.025792 3.614 0.000
L1.Vorarlberg 0.053873 0.022884 2.354 0.019
L1.Wien 0.034200 0.041871 0.817 0.414
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037280 0.118981 0.174035 0.143784 0.099996 0.087270 0.039578 0.212015
Kärnten 0.037280 1.000000 -0.018829 0.135095 0.052618 0.090224 0.440446 -0.060454 0.094055
Niederösterreich 0.118981 -0.018829 1.000000 0.323401 0.130200 0.282931 0.076766 0.161594 0.300716
Oberösterreich 0.174035 0.135095 0.323401 1.000000 0.220144 0.308558 0.168009 0.150635 0.251652
Salzburg 0.143784 0.052618 0.130200 0.220144 1.000000 0.129018 0.098954 0.114410 0.130454
Steiermark 0.099996 0.090224 0.282931 0.308558 0.129018 1.000000 0.138466 0.118388 0.050882
Tirol 0.087270 0.440446 0.076766 0.168009 0.098954 0.138466 1.000000 0.069461 0.148010
Vorarlberg 0.039578 -0.060454 0.161594 0.150635 0.114410 0.118388 0.069461 1.000000 0.007643
Wien 0.212015 0.094055 0.300716 0.251652 0.130454 0.050882 0.148010 0.007643 1.000000